package test.ground.service;

import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;

//@Component
public class CustomProxyProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object ori, String beanName) {
        //扩展bpp，返回代理对象
        if (ori instanceof InsA) {
            return Enhancer.create(InsA.class, (MethodInterceptor) (obj, method, args, proxy) -> {
                // 自定义代理逻辑
                return proxy.invokeSuper(obj, args);
            });
        }
        return ori;
    }
}